﻿using LibNiconico.NiconicoApi.Extentions;
using LibNiconico.NiconicoApi.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace LibNiconico.NiconicoApi.Alert
{
    /// <summary>
    /// ニコニコアラートストリーム情報取得レスポンス
    /// </summary>
    public class NicoAlertStreamInfoResponse : NicoApiInfoXmlResponseBase<NicoAlertError>
    {
        private NicoAlertStreamInfoResponse(XDocument document) : base(document) { }

        /// <summary>
        /// 要求したID
        /// </summary>
        public string RequestId { get; private set; }
        
        /// <summary>
        /// アラート用ストリーム情報
        /// </summary>
        public NicoAlertStreamInfo AlertStreamInfo
        {
            get;
            private set;
        }

        /// <summary>
        /// アラート用コミュニティ情報
        /// </summary>
        public NicoAlertCommunityInfo AlertCommunityInfo
        {
            get;
            private set;
        }

        /// <summary>
        /// エラーコード解析
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        protected override NicoAlertError ParseErrorCode(string code)
        {
            return NicoAlertError.Parse(code);
        }

        internal static NicoAlertStreamInfoResponse Parse(XDocument document)
        {
            var response = new NicoAlertStreamInfoResponse(document);
            var getStreamInfoElement = document.Element("getstreaminfo");
            response.RequestId = getStreamInfoElement.GetElementAsString("request_id");
            response.AlertStreamInfo = NicoAlertStreamInfo.Parse(getStreamInfoElement.Element("streaminfo"));
            response.AlertCommunityInfo = NicoAlertCommunityInfo.Parse(getStreamInfoElement.Element("communityinfo"));

            return response;

        }
    }
}
